#!/bin/env python3
# -*- coding:utf-8 -*-
"""
    [模块名]
    Add By : cdj <e4ting@qq.com> 2021-07-14 17:57:18
"""
from flask_restful import Resource
from flask         import redirect,request,make_response

from e4ting import log

# from poker import rooms,player

enable = True

class TexasPlayer(Resource):
    """玩家"""

    def get_game_info(self):
        user = self.info["name"]
        data = player.get_account_by_name(user)
        return data

    def create_game_info(self):
        user = self.info["name"]
        ret  = player.create_account_by_name(user)
        # data = player.get_account_by_name(user)
        return ret

    def join(self, data):
        log.info("加入房间")
        room_id = data.get("room", None)
        return

    def get(self, name=None):
        """创建玩家"""
        log.info(self.info)
        # uid = self.info["uid"]
        self.create_game_info()
        data = self.get_game_info()
        return {
            "code" : 200,
            "data"  : data,
        }

    def post(self, mod=None):
        """玩家动作"""
        # request.json

        ret = {}
        log.info(mod)
        data = request.json
        mod = data.get("mod", None)
        if not mod:
            return {
                "code" : 400,
                "data"  : "参数错误",
            }
        if mod == "join":
            ret = self.join(data)
        return {
            "code" : 200,
            "data"  : ret,
        }

